
import os

import yaml
# yml的相关操作

#往yaml文件中写入数据
def write_yaml(filename,data):
    file_path = os.path.join(os.getcwd(), "data", filename)
    print(f"Actual path: {file_path}")  # 打印实际的文件路径
    with open(file_path, mode="a+", encoding="utf-8") as f:
        yaml.safe_dump(data, stream=f)

#读取yaml文件中的数据
def read_yaml(filename,key):
    with open(os.getcwd()+"/data/"+filename,mode="r",encoding="utf-8") as f:
        data = yaml.safe_load(f)
        return data[key]

#清空
def clear_yaml(filename):
    with open(os.getcwd()+"/data/"+filename,mode="w",encoding="utf-8") as f:
        f.truncate()